use dta\DataSet_v28.dta, clear

egen partycabinet=sum(cabinet), by(year party)
keep if year>1944
keep if partycabinet>0 
replace rank=10 if rank>10

preserve
collapse cabinet, by(rank female)
tw (scatter cabinet rank if female==0, msymbol(S) mcolor(gray) connect(l) lpattern(solid) lcolor(black)) ///
   (scatter cabinet rank if female==1, msymbol(O) mcolor(black) connect(l) lpattern(solid) lcolor(black)), ///
title("") ytitle(Fraction promoted to cabinet) plotregion(lcolor(white) ilcolor(white)) graphregion(fcolor(white)) ///
ylabel(, grid angle(0))  xtitle(Rank, size(large)) yscale(range(0 0.3)) ylabel(0(0.1)0.3) xscale(reverse range(0.9 10.1)) ///
scheme(s1mono)  legend(off) text(0.12 1.1 "Men", color(gray)) text(0.25 2 "Women", color(black))
graph save figures/gph/a1.gph, replace
restore

foreach var in cabinet {
		estimates clear
		forval i = 1(1)10{
			eststo diff_`i': reg `var' female if rank==`i', r
		}
		
		
	coefplot diff_*, scheme(s1mono) vertical aseq swapnames drop(*cons*) ///
		yline(0, lcol(gray) lpattern(dash) lwidth(medthick)) yline(0.05 0.1 0.15, lcolor(gray*0.2)) ///
		xlab(1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8" 9 "9" 10 "10+") xsc(reverse) ///
		ylab(0(0.05)0.15,angle(0)) ///
		ytitle(Gender gap estimate (w-m)) ///
		xtitle(Rank, size(large)) ///
		msym(O) mcol(gs4) ciopts(col(gs4)) ///
		legend(off) title("", size(large)) plotregion(lcolor(white) ilcolor(white)) graphregion(fcolor(white))
		graph save figures/gph/_cabinet_cp.gph, replace
		
		
		esttab using tables/Table_Fig4.tex, replace style(tex) r2 se star(* 0.10 ** 0.05 *** 0.01) b(%9.3f) se(%9.3f) coeflabels(female "Women") ///
drop(_cons ) mtitles("Rank 1" "Rank 2" "Rank 3" "Rank 4" "Rank 5" "Rank 6" "Rank 7" "Rank 8" "Rank 9" "Rank 10+") nonotes ///
stats(r2 N, labels ("R$^2$" "N") fmt(3 0 3) ) ///
prehead("\begin{tabular}{l*{@M}{rr}}" "\hline") posthead(\hline) postfoot("\hline" "\end{tabular}")  
}

cd figures/gph/
graph combine a1.gph _cabinet_cp.gph, xcommon scheme(s1mono) col(1) 
graph export ../Figure4.pdf, replace
cd ../../